const { src, dest,series, parallel } = require('gulp')
const htmlmin = require('gulp-htmlmin')
const autoprefixer = require('gulp-autoprefixer')
const cleanCss = require('gulp-clean-css')
const uglify = require('gulp-uglify')
const babel = require('gulp-babel')
const imagemin = require('gulp-imagemin')
const _ = require('gulp-load-plugins')

function print(cb) {
    console.log(_)
    cb()
}
//处理html
function handlerHTML(cb) {
    src('./xiangmu/html/*.html')
    .pipe(htmlmin({
        collapseWhitespace:true
    }))
    .pipe(dest('dist/html'))
    cb()
}
//处理css
function handlerCSS(cb) {
    src('./xiangmu/css/*.css')
    .pipe(autoprefixer())
    .pipe(cleanCss())
    .pipe(dest('dist/css'))
    cb()
}
//处理js
function handlerJS(cb) {
    src('./xiangmu/js/*.js')
    .pipe(babel({
        presets:["es2015"]
    }))
    .pipe(uglify())
    .pipe(dest('dist/js'))
    cb()
}
//处理sass
function handlerSASS(cb) {
    src('./xiangmu/sass/*.scss')
    .pipe(autoprefixer())
    .pipe(cleanCss())
    .pipe(dest('dist/sass'))
    cb()
}
//处理网页图标
function handlerICO(cb) {
    src("./xiangmu/favicon.ico")
    .pipe(dest('./dist'))
    cb()
}
// 图片处理
function handlerIMG(cb){
    src(['./xiangmu/images/*.jpg', './xiangmu/images/*.png'])
    .pipe(imagemin())
    .pipe(dest('dist/images'))
    cb()
}
//导出任务
exports.default = parallel(handlerJS,handlerCSS,handlerHTML,handlerIMG,handlerICO,handlerSASS)